dz.user = {}

dz.user.follow = function (obj, task, user_id){
	if (obj.hasClass('loading')) return;
	
	var user_id = obj.attr('user-id');
	var task = obj.hasClass('checked')?'follow':'unfollow';
	
	obj.addClass('loading');
	$.ajax({
		type	: 'POST',
		url		:	dz.l('user/follow'),
		data	: {
			user_id	: user_id,
			task		: task
		},
		success	: function (res){			
			obj.removeClass('loading');
			if (parseInt(res['code'])==1){
				$('.btn-user-follow[user-id='+user_id+']').toggleClass('checked');
			}else{
				alert(res['mess']);
			}
		},
		dataType	: 'json'
	});
}

$(document).ready(function (){
	$('.btn-user-follow').click(function (e){
		e.preventDefault();
		
		dz.user.follow($(this));
	})
})